//
// Created by yunnan xu on 2020/11/17.
//

#ifndef ANDROIDGRAPHICSDEMOS_TEXTURE_H
#define ANDROIDGRAPHICSDEMOS_TEXTURE_H

#include <gles3/gl32.h>
#include <string>
#include <vector>
#include "GLESUtils.h"
#include <unordered_map>


enum TextureType{
    RAW = 0,
    ASTC = 1,
    ETC = 2,
};


class Texture
{
public:

    virtual ~Texture() = default;

protected:
    void LoadFromFile(const char * file_path);

    void * texFileContent;
    void * texRGBContent;
    int width;
    int height;
    int deep;

    TextureType tex_type;
    GLenum internal_tex_type;
    int channels;
    int n_bytes_to_read;
};

template<GraphicsAPI api> class Texture2D;
template<GraphicsAPI api> class CubeMapTexture;



template <class TextureType>
class IGLESTexture
{
public:

    GLuint GetTexture() {return texture;}
    GLuint GetTextureUnit() {return tex_unit_index;}
protected:

    GLuint texture;
    GLuint tex_unit_index;
};



template<>
class Texture2D<GraphicsAPI::GLESv3> : public Texture, public IGLESTexture<Texture2D<GraphicsAPI::GLESv3>>
{
public:

    Texture2D(const char * file_path, int texture_unit);
    Texture2D(GLenum internalformat, int levels, GLsizei width, GLsizei height, const std::unordered_map<int, int> * texture_2d_params, int texture_unit);

protected:
};


template<>
class CubeMapTexture<GraphicsAPI::GLESv3> : public Texture, public IGLESTexture<CubeMapTexture<GraphicsAPI::GLESv3>>
{
public:
    CubeMapTexture(std::vector<const char *> cube_map_file_path_list, int texture_unit);

protected:

};


#endif //ANDROIDGRAPHICSDEMOS_TEXTURE_H
